package com.api.hg;

import com.api.hg.action.DoorAaction;
import com.api.sw.duban.util.LogTool;
import jdk.nashorn.internal.ir.BlockLexicalContext;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;

import java.math.BigDecimal;
import java.math.RoundingMode;

//zt 0: 在库  1：再用 2：已报废 3：已借用 com.api.hg.DoorUtil
public class DoorUtil {
    private final static LogTool log = new LogTool("/log/assetlog/luolf/DoorUtil",false);
    /*
        获取总关的资产信息 syks  科室  zrr 责任人  dybm 对应部门
     */
    public String getZgCount(String lx,User user){
        //判断是否是中山海关管理员如果是的话 只要取 中山分部下面的 资产
        String subid="";
        String subdata="0";
        String sql="";
        int jsst= DoorAaction.checkRole(user);
        if("0".equals(lx)){
            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")){
                subid=getAllSub(0+"");
                sql="select count(1) counts from uf_swzczmxx where zczt not in(2,7,8)";//系统管理员不需要按部门统计
            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+"")){
                subid=getAllSub(BaseUtle.zshgsub+"");
                sql="select count(1) counts from uf_swzczmxx where dybm in ("+subid+")  and zczt not in(2,7,8)";//and ztzt<>7
            }else if(jsst==1&&DoorAaction.jsjsub.equals(user.getUserSubCompany1()+"")){//缉私局  海关的上面已经设置了
                subid=getAllSub(DoorAaction.jsjsub+"");
                sql="select count(1) counts from uf_swzczmxx where dybm in ("+subid+")  and zczt not in(2,7,8)";//and ztzt<>7
            }else {
                return "0";
            }
            //开始sql 查询
        }else  if("1".equals(lx)){//分部
            subid=getAllSub(user.getUserSubCompany1()+"");
            sql="select count(1) counts from uf_swzczmxx where dybm in ("+subid+") and zczt not in(2,7,8)";//and ztzt<>7
        }else  if("2".equals(lx)){//科室
            subid=getAllDep(user.getUserDepartment()+"");
            sql="select count(1) counts from uf_swzczmxx where syks in ("+subid+")  and zczt not in(2,7,8)";//and ztzt<>7
        }
        if(!"".equals(sql)){
            RecordSet re=new RecordSet();
            re.execute(sql);
            if(re.next()){
                subdata=Util.getIntValue(re.getString("counts"),0)+"";
            }
            log.writeLog("getZgCount(获取全关实物资产总数)-->"+sql);
            log.writeLog("getZgCount(获取全关实物资产总数结果)-->"+subdata);
        }

        return subdata;
    }
    /*
        全关资产总数
         海关资产和非海关资产的数量（表单字段里有个产权状况）
         select zclx from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id and b.id in (1,2,4,5,6,7,8,9,10,11,12)
     */
    public String getZgCountWhere(String lx,User user){
        //判断是否是中山海关管理员如果是的话 只要取 中山分部下面的 资产
        String subid="";
        String subdata="0";
        String sql="";
        int jsst= DoorAaction.checkRole(user);
        if("0".equals(lx)){
            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")){
                subid=getAllSub(0+"");
                sql="select count(1) counts from uf_swzczmxx where zczt not in(2,7,8)";//and ztzt<>7
            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+"")){
                subid=getAllSub(BaseUtle.zshgsub+"");
                sql="select count(1) counts from uf_swzczmxx where dybm in ("+subid+") and zczt not in(2,7,8)";//and ztzt<>7
            }else if(jsst==1&&DoorAaction.jsjsub.equals(user.getUserSubCompany1()+"")){//缉私局  海关的上面已经设置了
                subid=getAllSub(DoorAaction.jsjsub+"");
                sql="select count(1) counts from uf_swzczmxx where dybm in ("+subid+")  and zczt not in(2,7,8)";//and ztzt<>7
            }else {
                return "0";
            }
            //开始sql 查询

        }
        if(!"".equals(sql)){
            RecordSet re=new RecordSet();
            re.execute(sql);
            log.writeLog("获取全关资产总数-->"+sql);
            if(re.next()){
                subdata=Util.getIntValue(re.getString("counts"),0)+"";
            }
        }

        return subdata;
    }

    /*
      获取海关资产总数
   */
    public String getHgount(String lx,User user){
        //判断是否是中山海关管理员如果是的话 只要取 中山分部下面的 资产
        String subid="";
        String subdata="0";
        String sql="";
        int jsst= DoorAaction.checkRole(user);
        if("0".equals(lx)){
            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")){
                subid=getAllSub(0+"");
                sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id   and zczt not in(2,7,8) isnull(a.cqzk,-1) in (0,3)";//系统管理员统计所有的
            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+"")){
                subid=getAllSub(BaseUtle.zshgsub+"");
                sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and a.dybm in ("+subid+")  and zczt not in(2,7,8) isnull(a.cqzk,-1) in (0,3)";
            }else if(jsst==1&&DoorAaction.jsjsub.equals(user.getUserSubCompany1()+"")){//缉私局  海关的上面已经设置了
                subid=getAllSub(DoorAaction.jsjsub+"");
                sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and a.dybm in ("+subid+")  and zczt not in(2,7,8) isnull(a.cqzk,-1) in (0,3)";
            }else {
                return "0";
            }
            //开始sql 查询
        }
        if(!"".equals(sql)){
            RecordSet re=new RecordSet();
            re.execute(sql);
            log.writeLog("获取海关资产总数-->"+sql);
            if(re.next()){
                subdata=Util.getIntValue(re.getString("counts"),0)+"";
            }
        }
        return subdata;
    }

    /*
      获取非海关资产总数
    */
    public String getFhgount(String lx,User user){
        //判断是否是中山海关管理员如果是的话 只要取 中山分部下面的 资产
        String subid="";
        String subdata="0";
        String sql="";
        int jsst= DoorAaction.checkRole(user);
        if("0".equals(lx)){
            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")){
                subid=getAllSub(0+"");
                //开始sql 查询
                sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id   and zczt not in(2,7,8) and  isnull(a.cqzk,-1) in (1,2)";//and ztzt<>7
            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+"")){
                subid=getAllSub(BaseUtle.zshgsub+"");
                //开始sql 查询
                sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and a.dybm in ("+subid+")  and zczt not in(2,7,8) and isnull(a.cqzk,-1) in (1,2)";//and ztzt<>7
            }else if(jsst==1&&DoorAaction.jsjsub.equals(user.getUserSubCompany1()+"")){//缉私局  海关的上面已经设置了
                subid=getAllSub(DoorAaction.jsjsub+"");
                //开始sql 查询
                sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and a.dybm in ("+subid+")  and zczt not in(2,7,8) and  isnull(a.cqzk,-1) in (1,2)";//and ztzt<>7
            }else {
                return "0";
            }

        }
        if(!"".equals(sql)){
            RecordSet re=new RecordSet();
            re.execute(sql);
            log.writeLog("获取非海关资产总数-->"+sql);
            if(re.next()){
                subdata=Util.getIntValue(re.getString("counts"),0)+"";
            }
        }
        return subdata;
    }
    /*
        获取在库资产总数
     */
    public String getZcCount(String lx,User user){
        //判断是否是中山海关管理员如果是的话 只要取 中山分部下面的 资产
        String subid="";
        String subdata="0";
        String sql="";
        int jsst= DoorAaction.checkRole(user);
        if("0".equals(lx)){
            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")){
                subid=getAllSub(0+"");
                //开始sql 查询
                sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and isnull(a.zczt,-1) in (0) ";//and ztzt<>7
            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+"")){
                subid=getAllSub(BaseUtle.zshgsub+"");
                //开始sql 查询
                sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and a.dybm in ("+subid+")  and isnull(a.zczt,-1) in (0) ";//and ztzt<>7
            }else if(jsst==1&&DoorAaction.jsjsub.equals(user.getUserSubCompany1()+"")){//缉私局  海关的上面已经设置了
                subid=getAllSub(DoorAaction.jsjsub+"");
                //开始sql 查询
                sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and a.dybm in ("+subid+")  and isnull(a.zczt,-1) in (0) ";//and ztzt<>7
            }else {
                return "0";
            }

        }
        if(!"".equals(sql)){
            RecordSet re=new RecordSet();
            re.execute(sql);
            log.writeLog("获取在库资产总数-->"+sql);
            if(re.next()){
                subdata=Util.getIntValue(re.getString("counts"),0)+"";
            }
        }
        return subdata;
    }

    /*
    获取台式机资产总数
 */
    public String getTsjCount(String lx,User user){
        //判断是否是中山海关管理员如果是的话 只要取 中山分部下面的 资产
        String subid="";
        String subdata="0";
        String sql="";
        int jsst= DoorAaction.checkRole(user);
        if("0".equals(lx)){
            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")){
                subid=getAllSub(0+"");
                //开始sql 查询
                sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and b.id=1 and zczt not in(2,7,8) ";//and ztzt<>7
            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+"")){
                subid=getAllSub(BaseUtle.zshgsub+"");
                //开始sql 查询
                sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and b.id=1 and a.dybm in ("+subid+")  and zczt not in(2,7,8) ";//and ztzt<>7
            }else if(jsst==1&&DoorAaction.jsjsub.equals(user.getUserSubCompany1()+"")){//缉私局  海关的上面已经设置了
                subid=getAllSub(DoorAaction.jsjsub+"");
                //开始sql 查询
                sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and b.id=1 and a.dybm in ("+subid+")  and zczt not in(2,7,8) ";//and ztzt<>7
            }else {
                return "0";
            }

        }
        if(!"".equals(sql)){
            RecordSet re=new RecordSet();
            re.execute(sql);
            log.writeLog("获取台式机资产总数-->"+sql);
            if(re.next()){
                subdata=Util.getIntValue(re.getString("counts"),0)+"";
            }
        }
        return subdata;
    }

    /*
    获取便携式计算机资产总数
 */
    public String getBxsjsjCount(String lx,User user){
        //判断是否是中山海关管理员如果是的话 只要取 中山分部下面的 资产
        String subid="";
        String subdata="0";
        String sql="";
        int jsst= DoorAaction.checkRole(user);
        if("0".equals(lx)){
            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")){
                subid=getAllSub(0+"");
                //开始sql 查询
                sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and b.id=2 and zczt not in(2,7,8) ";//and ztzt<>7
            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+"")){
                subid=getAllSub(BaseUtle.zshgsub+"");
                //开始sql 查询
                sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and b.id=2 and a.dybm in ("+subid+")  and zczt not in(2,7,8) ";//and ztzt<>7
            }else if(jsst==1&&DoorAaction.jsjsub.equals(user.getUserSubCompany1()+"")){//缉私局  海关的上面已经设置了
                subid=getAllSub(DoorAaction.jsjsub+"");
                //开始sql 查询
                sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and b.id=2 and a.dybm in ("+subid+")  and zczt not in(2,7,8) ";//and ztzt<>7
            }else {
                return "0";
            }
        }
        if(!"".equals(sql)){
            RecordSet re=new RecordSet();
            re.execute(sql);
            log.writeLog("获取便携式计算机资产总数-->"+sql);
            if(re.next()){
                subdata=Util.getIntValue(re.getString("counts"),0)+"";
            }
        }
        return subdata;
    }
    /*
       获取打印机资产总数
    */
    public String getDyjCount(String lx,User user){
        //判断是否是中山海关管理员如果是的话 只要取 中山分部下面的 资产
        String subid="";
        String subdata="0";
        String sql="";
        int jsst= DoorAaction.checkRole(user);
        if("0".equals(lx)){
            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")){
                subid=getAllSub(0+"");
                //开始sql 查询
                sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and b.id in(10,11,12,13) and zczt not in(2,7,8) ";//and ztzt<>7
            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+"")){
                subid=getAllSub(BaseUtle.zshgsub+"");
                //开始sql 查询
                sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and b.id in(10,11,12,13) and a.dybm in ("+subid+")  and zczt not in(2,7,8) ";//and ztzt<>7
            }else if(jsst==1&&DoorAaction.jsjsub.equals(user.getUserSubCompany1()+"")){//缉私局  海关的上面已经设置了
                subid=getAllSub(DoorAaction.jsjsub+"");
                //开始sql 查询
                sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and b.id in(10,11,12,13) and a.dybm in ("+subid+")  and zczt not in(2,7,8) ";//and ztzt<>7
            }else {
                return "0";
            }
        }
        if(!"".equals(sql)){
            RecordSet re=new RecordSet();
            re.execute(sql);
            log.writeLog("获取打印机资产总数-->"+sql);
            if(re.next()){
                subdata=Util.getIntValue(re.getString("counts"),0)+"";
            }
        }
        return subdata;
    }
    /*
    获取显示器资产总数
    */
    public String getXsqCount(String lx,User user){
        //判断是否是中山海关管理员如果是的话 只要取 中山分部下面的 资产
        String subid="";
        String subdata="0";
        String sql="";
        int jsst= DoorAaction.checkRole(user);
        if("0".equals(lx)){
            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")){
                subid=getAllSub(0+"");
                //开始sql 查询
                sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and b.id =4 and isnull(zczt,-1)<>7 and isnull(zczt,-1)<>8 ";//and ztzt<>7
            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+"")){
                subid=getAllSub(BaseUtle.zshgsub+"");
                //开始sql 查询
                sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and b.id =4 and a.dybm in ("+subid+")  and zczt not in(2,7,8) ";//and ztzt<>7
            }else if(jsst==1&&DoorAaction.jsjsub.equals(user.getUserSubCompany1()+"")){//缉私局  海关的上面已经设置了
                subid=getAllSub(DoorAaction.jsjsub+"");
                //开始sql 查询
                sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and b.id =4 and a.dybm in ("+subid+")  and zczt not in(2,7,8) ";//and ztzt<>7
            }else {
                return "0";
            }
        }
        if(!"".equals(sql)){
            RecordSet re=new RecordSet();
            re.execute(sql);
            log.writeLog("获取打印机资产总数-->"+sql);
            if(re.next()){
                subdata=Util.getIntValue(re.getString("counts"),0)+"";
            }
        }
        return subdata;
    }
    /*
        获取在库  0:全关在库  1：部门在库 2 科室在库 3个人在库
     */
    public String getZk(String lx, User user){
        String count="0";
        String sql="";
        if("0".equals(lx)){
            String subid="";
            int jsst= DoorAaction.checkRole(user);
            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")){
                subid=getAllSub(0+"");
                sql="select count(1) counts from uf_swzczmxx where  isnull(zczt,-1) = 0";
            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+"")){
                subid=getAllSub(BaseUtle.zshgsub+"");
                sql="select count(1) counts from uf_swzczmxx where dybm in ("+subid+") and isnull(zczt,-1) = 0";
            }else if(jsst==1&&DoorAaction.jsjsub.equals(user.getUserSubCompany1()+"")){//缉私局  海关的上面已经设置了
                subid=getAllSub(DoorAaction.jsjsub+"");
                sql="select count(1) counts from uf_swzczmxx where dybm in ("+subid+") and isnull(zczt,-1) = 0";
            }else {
                return "0";
            }
        }else if("1".equals(lx)){//部门  也是就是 OA 的分部
            String subid="";
            subid=getAllSub(user.getUserSubCompany1()+"");
            sql="select count(1) counts from uf_swzczmxx where dybm in ("+subid+") and isnull(zczt,-1) = 0";
        }else if("2".equals(lx)){//部门
            String subid= getAllDep(user.getUserDepartment()+"");
            sql="select count(1) counts from uf_swzczmxx where syks in ("+subid+") and isnull(zczt,-1) = 0";
        }
        if(!"".equals(sql)){
            RecordSet re=new RecordSet();
            log.writeLog("getZk-->"+sql);
            re.execute(sql);
            if(re.next()){
                count=Util.getIntValue(re.getString("counts"),0)+"";
            }
        }

        return count;
    }
    /*
        获取在用   0:全关在库  1：部门在库 2 科室在库 3个人在库
     */
    public String getZy(String lx, User user){
        String count="0";
        String sql="";
        if("0".equals(lx)){
            String subid="";
            int jsst= DoorAaction.checkRole(user);
            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")){
                subid=getAllSub(0+"");
                sql="select count(1) counts from uf_swzczmxx where  isnull(zczt,-1) =1";
            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")){
                subid=getAllSub(BaseUtle.zshgsub+"");
                sql="select count(1) counts from uf_swzczmxx where dybm in ("+subid+") and isnull(zczt,-1) =1";
            }else if(jsst==1&&DoorAaction.jsjsub.equals(user.getUserSubCompany1()+"")){//缉私局  海关的上面已经设置了
                subid=getAllSub(DoorAaction.jsjsub+"");
                sql="select count(1) counts from uf_swzczmxx where dybm in ("+subid+") and isnull(zczt,-1) =1";
            }else {
                return "0";
            }
        }else if("1".equals(lx)){//部门  也是就是 OA 的分部
            String subid="";
            subid=getAllSub(user.getUserSubCompany1()+"");
            sql="select count(1) counts from uf_swzczmxx where dybm in ("+subid+") and isnull(zczt,-1) =1";
        }else if("2".equals(lx)){//部门
            String subid= getAllDep(user.getUserDepartment()+"");
            sql="select count(1) counts from uf_swzczmxx where syks in ("+subid+") and isnull(zczt,-1) =1";
        }else if("3".equals(lx)){//个人
            String subid= getAllDep(user.getUserDepartment()+"");
            sql="select count(1) counts from uf_swzczmxx where zrr in ("+user.getUID()+") and isnull(zczt,-1) =1";
        }
        if(!"".equals(sql)){
            RecordSet re=new RecordSet();
            log.writeLog("getZy-->"+sql);
            re.execute(sql);
            if(re.next()){
                count=Util.getIntValue(re.getString("counts"),0)+"";
            }
        }

        return count;
    }
    /*
      获取借用   0:全关在库  1：部门在库 2 科室在库 3个人在库
   */
    public String getJy(String lx, User user ){

        String count="0";
        String sql="";
        if("0".equals(lx)){
            String subid="";
            int jsst= DoorAaction.checkRole(user);
            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")){
                subid=getAllSub(0+"");
            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")){
                subid=getAllSub(BaseUtle.zshgsub+"");
            }else if(jsst==1&&DoorAaction.jsjsub.equals(user.getUserSubCompany1()+"")){//缉私局  海关的上面已经设置了
                subid=getAllSub(DoorAaction.jsjsub+"");
            }else {
                return "0";
            }
            sql="select count(1) counts from uf_swzczmxx where dybm in ("+subid+") and isnull(zczt,-1) =3";
        }else if("1".equals(lx)){//部门  也是就是 OA 的分部
            String subid="";
            subid=getAllSub(user.getUserSubCompany1()+"");
            sql="select count(1) counts from uf_swzczmxx where dybm in ("+subid+") and isnull(zczt,-1) =3";
        }else if("2".equals(lx)){//部门
            String subid= getAllDep(user.getUserDepartment()+"");
            sql="select count(1) counts from uf_swzczmxx where syks in ("+subid+") and isnull(zczt,-1) =3";
        }else if("3".equals(lx)){//个人
            String subid= getAllDep(user.getUserDepartment()+"");
            sql="select count(1) counts from uf_swzczmxx where zrr in ("+user.getUID()+") and isnull(zczt,-1) =3";
        }
        if(!"".equals(sql)){
            RecordSet re=new RecordSet();
            log.writeLog("getJy-->"+sql);
            re.execute(sql);
            if(re.next()){
                count=Util.getIntValue(re.getString("counts"),0)+"";
            }
        }

        return count;
    }
    /*
      获取已报废  0:全关  1：部门 2 科室 3个
   */
    public String getYBf(String lx, User user){
        String count="0";
        String sql="";
        /*
        if("0".equals(lx)){
            String subid="";
            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")){
                subid=getAllSub(0+"");
            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")){
                subid=getAllSub(BaseUtle.zshgsub+"");
            }else{
                return "0";
            }
            sql="select count(1) counts from uf_swzczmxx where dybm in ("+subid+") and isnull(zczt,-1) =7";//isnull(zczt,-1) =7
        }else if("1".equals(lx)){//部门  也是就是 OA 的分部
            String subid="";
            subid=getAllSub(user.getUserSubCompany1()+"");
            sql="select count(1) counts from uf_swzczmxx where dybm in ("+subid+") and isnull(zczt,-1) =7";
        }else if("2".equals(lx)){//部门
            String subid= getAllDep(user.getUserDepartment()+"");
            sql="select count(1) counts from uf_swzczmxx where syks in ("+subid+") and isnull(zczt,-1) =7";
        }else if("3".equals(lx)){//个人
            String subid= getAllDep(user.getUserDepartment()+"");
            sql="select count(1) counts from uf_swzczmxx where zrr in ("+user.getUID()+") and isnull(zczt,-1) =7";
        }
         */
        sql="select count(1) counts from uf_swzczmxx where isnull(zczt,-1) =7";//isnull(zczt,-1) =7
        if(!"".equals(sql)){
            RecordSet re=new RecordSet();
            log.writeLog("getYBf-->"+sql);
            re.execute(sql);
            if(re.next()){
                count=Util.getIntValue(re.getString("counts"),0)+"";
            }
        }

        return count;
    }

    /*
      获取报废中  0:全关在库  1：部门在库 2 科室在库 3个人在库
    */
    public String getBfZ(String lx, User user){

        String count="0";
        String sql="";
        if("0".equals(lx)){
            String subid="";
            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")){
                subid=getAllSub(0+"");
                sql="select count(1) counts from uf_swzczmxx where isnull(zczt,-1) =2";
            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zshgsub+"")){
                subid=getAllSub(BaseUtle.zshgsub+"");
                sql="select count(1) counts from uf_swzczmxx where dybm in ("+subid+") and isnull(zczt,-1) =2";
            }else{
                return "0";
            }
        }else if("1".equals(lx)){//部门  也是就是 OA 的分部
            String subid="";
            subid=getAllSub(user.getUserSubCompany1()+"");
            sql="select count(1) counts from uf_swzczmxx where dybm in ("+subid+") and isnull(zczt,-1) =2";
        }else if("2".equals(lx)){//部门
            String subid= getAllDep(user.getUserDepartment()+"");
            sql="select count(1) counts from uf_swzczmxx where syks in ("+subid+") and isnull(zczt,-1) =2";
        }else if("3".equals(lx)){//个人
            String subid= getAllDep(user.getUserDepartment()+"");
            sql="select count(1) counts from uf_swzczmxx where zrr in ("+user.getUID()+") and isnull(zczt,-1) =2";
        }
        if(!"".equals(sql)){
            RecordSet re=new RecordSet();
            log.writeLog("getBfZ-->"+sql);
            re.execute(sql);
            if(re.next()){
                count=Util.getIntValue(re.getString("counts"),0)+"";
            }
        }
        return count;
    }

    /*
      获取个人资产总数
   */
    public String getSinglezC(User user){

        String count="0";
        String sql="";
        sql="select count(1) counts from uf_swzczmxx where zrr in ("+user.getUID()+") and isnull(zczt,-1)  in (1,3)";
        if(!"".equals(sql)){
            RecordSet re=new RecordSet();
            re.execute(sql);
            if(re.next()){
                count=Util.getIntValue(re.getString("counts"),0)+"";
            }
        }
        return count;
    }
    /*
        获取 当前分部 的 所有的 子分部
     */
    public String getAllSub(String supsubid){
        String substr="";
        supsubid=Util.null2String(supsubid).trim();
        RecordSet re=new RecordSet();
        String sql="with Department as " +
                " (select *,0 as Level from HrmSubCompany where isnull(supsubcomid,0) in ("+supsubid+") and isnull(canceled,0)=0 " +
                " union all select d.*,Department.Level + 1 from Department,HrmSubCompany d where Department.id=d.supsubcomid and isnull(d.canceled,0)=0) " +
                " select distinct id,SubCompanyname,Level from Department " ;
                //" where id not in(  select id from HrmSubCompany where id =29 or supsubcomid =29 and canceled<>1) ";//增加过滤
        //if("0".equals(supsubid)) sql += " where supsubcomid not in(5,29) and id not in (5,29,13,8,15,6,7,41,40,39) ";//增加过滤事业单位分部id huangwm
        log.writeLog("getAllSub获取当前用户对应权限的分部id--->"+sql);
        re.execute(sql);
        while(re.next()){
            String id= Util.null2String(re.getString("id")) ;
            substr=substr+id+",";
        }
        if(!"".equals(substr)){
            substr=substr+supsubid;
            if(substr.endsWith(",")){
                substr=substr.substring(0,substr.length()-1);
            }
        }else{
            return supsubid;
        }
        return substr;
    }
    /*
    获取除缉私局外的所有分部
 */
    public String getAllSubNotJSJ(String supsubid){
        String substr="";
        supsubid=Util.null2String(supsubid).trim();
        RecordSet re=new RecordSet();
        String sql="with Department as " +
                " (select *,0 as Level from HrmSubCompany where isnull(supsubcomid,0) in ("+supsubid+") and isnull(canceled,0)=0 " +
                " union all select d.*,Department.Level + 1 from Department,HrmSubCompany d where Department.id=d.supsubcomid and isnull(d.canceled,0)=0) " +
                " select distinct id,SubCompanyname,Level from Department " +
                " where id not in(  select id from HrmSubCompany where id =29 or supsubcomid =29 and canceled<>1) ";//增加过滤缉私局
        //if("0".equals(supsubid)) sql += " where supsubcomid not in(5,29) and id not in (5,29,13,8,15,6,7,41,40,39) ";//增加过滤事业单位分部id huangwm
        log.writeLog("获取除缉私局外的所有分部id--->"+sql);
        re.execute(sql);
        while(re.next()){
            String id= Util.null2String(re.getString("id")) ;
            substr=substr+id+",";
        }
        if(!"".equals(substr)){
            substr=substr+supsubid;
            if(substr.endsWith(",")){
                substr=substr.substring(0,substr.length()-1);
            }
        }else{
            return supsubid;
        }
        return substr;
    }
    /*
      获取 当前分部 的 所有的 子分部
   */
    public String getAllDep(String supsubid){
        String substr="";
        supsubid=Util.null2String(supsubid).trim();
        RecordSet re=new RecordSet();
        String sql="with Department as  " +
                " (select *,0 as Level from Hrmdepartment where isnull(supdepid,0) in ("+supsubid+") and isnull(canceled,0)=0 " +
                " union all select d.*,Department.Level + 1 from Department,Hrmdepartment d where Department.id=d.supdepid and isnull(d.canceled,0)=0)  " +
                " select distinct id,departmentname,Level from Department ";
        log.writeLog("getAllDep--->"+sql);
        re.execute(sql);
        while(re.next()){
            String id= Util.null2String(re.getString("id")) ;
            substr=substr+id+",";
        }
        if(!"".equals(substr)){
            substr=substr+supsubid;
            if(substr.endsWith(",")){
                substr=substr.substring(0,substr.length()-1);
            }
        }else{
            return supsubid;
        }
        return substr;
    }
    /*
        获取帐时不符率
     */
    public  String getBflBySub(String subid){

        RecordSet re=new RecordSet();
        String bfl="0";
        //String sql="select *  from uf_zsbfl_view where id="+subid;
        String sql="select *  from uf_gbzcdp where bm="+subid;
        re.execute(sql);
        if(re.next()){
           double xfs=Util.getDoubleValue(re.getString("xfs"), 0);
           double bfs=Util.getDoubleValue(re.getString("bfs"), 0);
           double gbzcs=Util.getDoubleValue(re.getString("gbzcs"), 0);
            log.writeLog("getBflBySub====部门id "+subid+" 实物相符数量为"+xfs+"  不符数量为"+bfs+"  关保资产数为"+gbzcs);
           if((bfs+xfs)<=0){
               return "0";
           }
            //bfl= getSe(bfs,(bfs+xfs))+"";
            bfl= getSe(bfs,gbzcs)+"";
        }
        log.writeLog("====部门id "+subid+" 帐实不符率为"+bfl);
        return bfl;

        /*
        //huangwm
        RecordSet rs1 = new RecordSet();
        String sql1 = "select count(uf_swzczmxx.id) as swsl from uf_swzczmxx right join uf_gbxtzczmxx on uf_swzczmxx.xzgbxtzc=uf_gbxtzczmxx.kpwybs where dybm in ("+subid+")";
        int xfsl = 0;
        RecordSet rs2 = new RecordSet();
        String sql2 = "select count(id)as gbsl from uf_gbxtzczmxx where sybm in ("+subid+")";
        int zcsl = 0;
        if(rs1.execute(sql1)&&rs1.next()) xfsl = rs1.getInt(1);
        if(rs2.execute(sql2)&&rs2.next()) zcsl = rs2.getInt(1);
        log.writeLog("====部门id "+subid+" 实物相符数量为"+xfsl+"  关保资产数量为"+zcsl);
        BigDecimal a = new BigDecimal(xfsl);
        BigDecimal b = new BigDecimal(zcsl);
        double jsbfl = (1.00-a.divide(b,4,BigDecimal.ROUND_HALF_UP).doubleValue())*100;
        double sjbfl = new BigDecimal(jsbfl).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
        log.writeLog("====部门id "+subid+" 帐实不符率为"+sjbfl);
        return  String.valueOf(sjbfl);
         */

    }
    public double getSe(double all,double newsl){
        double wsdj=0.00;
        double sjbfl=0.00;
        try{
            BigDecimal allBig=new BigDecimal(all);
            BigDecimal newslBig=new BigDecimal(newsl);
            //wsdj=allBig.divide(newslBig,2,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100")).doubleValue();
            //huangwm 修改 主要避免四舍五入
            wsdj=allBig.divide(newslBig,4,BigDecimal.ROUND_HALF_UP).doubleValue()*100;
            sjbfl=new BigDecimal(wsdj).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
        }catch(Exception e){

        }
        return sjbfl;
    }
    /*
        获取全关帐实不符率
        if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")){
                subid=getAllSub(0+"");
            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zshgsub+"")){
                subid=getAllSub(BaseUtle.zshgsub+"");
            }else{
                return "0";
            }
     */
    public  String getAllBsBfl(){
        RecordSet re=new RecordSet();
        String bfl="0";
        String sql=" select t.*,round(cast((((t.c2-t.c1)*1.0)/t.c2) as float),2)*100 as bfl from (";
        sql+= " select (select count(1)  from uf_swzczmxx where isnull(dybm,0)>0) as c1,(select count(1) from uf_gbxtzczmxx)as c2 ) t";
        re.execute(sql);
        while(re.next()){
            bfl=Util.getDoubleValue(re.getString("bfl"), 0)+"";
        }
        return bfl;
    }


    public  String getAllBsBflV2(User user){
        RecordSet re=new RecordSet();
        String subid="";
        String bfl="0";
        if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")){
            //subid=getAllSub(0+"");
            subid=getAllSubNotJSJ(0+"");
            RecordSet getGBsl = new RecordSet();
                String getAll = "select count(*) as allyc,(select count(id)　from uf_gbxtzczmxx where kpzt not in (5,9,6,7,8) )  as allgb  from uf_uf_gbxtzczmxxexc where (sfyxz=1 or sfyxz is null ) and sybm in (select id from HrmSubCompany where canceled<>1 and id<>29 and supsubcomid<>29)";
            getGBsl.execute(getAll);
            getGBsl.next();
            double allyc=Util.getDoubleValue(getGBsl.getString("allyc"), 0);
            double allgb=Util.getDoubleValue(getGBsl.getString("allgb"), 0);
            bfl= getSe(allyc,allgb)+"";
            log.writeLog("=====管理员查看返回异常总数/关保资产过滤总数====="+bfl);
            return  bfl;
        }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zshgsub+"")){
            subid=getAllSub(BaseUtle.zshgsub+"");
        }else{
            subid="-1";
        }

        //String sql=" select t.*,round(cast((((t.c2-t.c1)*1.0)/t.c2) as float),2)*100 as bfl from (";
        //sql+= " select (select count(1)  from uf_swzczmxx where isnull(dybm,0)>0) as c1,(select count(1) from uf_gbxtzczmxx)as c2 ) t";
        String sql="select sum(isnull(xfs,0)) xfs,sum(isnull(bfs,0)) bfs,sum(isnull(gbzcs,0)) gbzcs   from uf_gbzcdp where bm in ("+subid+")";
        re.execute(sql);
        while(re.next()){
            double xfs=Util.getDoubleValue(re.getString("xfs"), 0);
            double bfs=Util.getDoubleValue(re.getString("bfs"), 0);
            double gbzcs=Util.getDoubleValue(re.getString("gbzcs"), 0);
            log.writeLog("部门id( "+subid+" )"+"相符数量( "+xfs+" )"+"不符数量( "+bfs+" )"+"关保资产数( "+gbzcs+" )");
            if((bfs+xfs)<=0){
                return "0";
            }
            //bfl= getSe(bfs,(bfs+xfs))+"";
            bfl= getSe(bfs,gbzcs)+"";
        }
        log.writeLog("=======本次查看帐实不符率为"+bfl+"=======");
        return bfl;
        /*
        //huangwm
        RecordSet rs1 = new RecordSet();
        String sql1 = "select count(uf_swzczmxx.id) as swsl from uf_swzczmxx right join uf_gbxtzczmxx on uf_swzczmxx.xzgbxtzc=uf_gbxtzczmxx.kpwybs where dybm in ("+subid+")";
        int xfsl = 0;
        RecordSet rs2 = new RecordSet();
        String sql2 = "select count(id)as gbsl from uf_gbxtzczmxx where sybm in ("+subid+")";
        int zcsl = 0;
        if(rs1.execute(sql1)&&rs1.next()) xfsl = rs1.getInt(1);
        if(rs2.execute(sql2)&&rs2.next()) zcsl = rs2.getInt(1);
        log.writeLog("=====管理员查看=====");
        log.writeLog("部门id( "+subid+" )");
        log.writeLog("相符数量( "+xfsl+" )");
        log.writeLog("资产总数( "+zcsl+" )");
        BigDecimal a = new BigDecimal(xfsl);
        BigDecimal b = new BigDecimal(zcsl);
        double jsbfl = (1.00-a.divide(b,4,BigDecimal.ROUND_HALF_UP).doubleValue())*100;
        double sjbfl = new BigDecimal(jsbfl).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
        log.writeLog("=======管理员查看帐实不符率为"+sjbfl+"=======");
        return  sjbfl;
         */

    }
    /*
        关领导视图数量显示
        全关设备：跟现有全关视图的保持一致
        资产总值：取实物表产权状况为海关资产、事业单位资产时的单价统计
        海关设备数量：产权状况为海关资产的数量
        事业单位设备数量：产权状况为事业单位资产的数量
     */
    /*
            资产总值：取实物表产权状况为海关资产、事业单位资产时的单价统计
     */
    public  String getAssetZz(User user){
        String subid="";
        if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")){
            subid=getAllSub(0+"");
        }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+"")) {
            subid = getAllSub(BaseUtle.zshgsub + "");
        }else{
            subid = getAllSub(user.getUserSubCompany1()+ "");
        }
        RecordSet re=new RecordSet();
        String zz="0";
        //String sql="select sum(isnull(dj,0)) djsum  from uf_swzczmxx where dybm in ("+subid+") and isnull(cqzk,-1) in (0,1)";
        String sql="select sum(isnull(dj,0)) djsum  from uf_swzczmxx where isnull(cqzk,-1) in (0,1)";
        re.execute(sql);
        while(re.next()){
            //zz=Util.getDoubleValue(re.getString("djsum"), 0)+"";
            zz = re.getString("djsum");
        }
        return zz;
    }
    /*
        类型 单位数量  0：海关  1：事业单位
     */
    public String getCountBylx(User user,String lx){
        String subid="";
        String sql="";
        if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")){
            subid=getAllSub(0+"");
            sql="select count(1)  counts from uf_swzczmxx where isnull(cqzk,-1) in ("+lx+")"; //系统管理员
        }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+"")) {
            subid = getAllSub(BaseUtle.zshgsub + "");
            sql="select count(1)  counts from uf_swzczmxx where dybm in ("+subid+") and isnull(cqzk,-1) in ("+lx+")";
        }else{
            subid = getAllSub(user.getUserSubCompany1()+ "");
            sql="select count(1)  counts from uf_swzczmxx where dybm in ("+subid+") and isnull(cqzk,-1) in ("+lx+")";
        }
        RecordSet re=new RecordSet();
        String bfl="0";
        re.execute(sql);
        while(re.next()){
            bfl=Util.getIntValue(re.getString("counts"), 0)+"";
        }
        return bfl;
    }

    /**
     * 获取全关设备总数 关领导视图 huangwm
     * @return
     */
    public String getZgCount_gld(){
        String sql = sql="select count(1) counts from uf_swzczmxx where zczt not in(2,7,8)";
        log.writeLog("获取全关设备总数 关领导视图 huangwm>>"+sql);
        RecordSet rs = new RecordSet();
        rs.execute(sql);
        rs.next();
        return rs.getString("counts");
    }
    /**
     * 获取海关资产设备总数 关领导视图 huangwm
     * @return
     */
    public String getHgCount_gld(){
        String  sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id   and zczt not in(2,7,8) and  isnull(a.cqzk,-1) in (0,3)";//and ztzt<>7
        log.writeLog("获取海关资产设备总数 关领导视图 huangwm>>"+sql);
        RecordSet rs = new RecordSet();
        rs.execute(sql);
        rs.next();
        return rs.getString("counts");
    }
    /**
     * 获取非海关资产设备总数 关领导视图 huangwm
     * @return
     */
    public String getFhgCount_gld(){
        String sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and zczt not in(2,7,8) and  isnull(a.cqzk,-1) in (1,2)";//and ztzt<>7
        log.writeLog("获取非海关资产设备总数 关领导视图 huangwm>>"+sql);
        RecordSet rs = new RecordSet();
        rs.execute(sql);
        rs.next();
        return rs.getString("counts");
    }
    /**
     * 获取在库资产设备总数 关领导视图 huangwm
     * @return
     */
    public String getZkCount_gld(){
        String sql="select count(1) counts from uf_swzczmxx where  isnull(zczt,-1) =0";
        RecordSet rs = new RecordSet();
        rs.execute(sql);
        rs.next();
        return rs.getString("counts");
    }
    /**
     * 获取台式机资产设备总数 关领导视图 huangwm
     * @return
     */
    public String getTsjCount_gld(){
        String sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and b.id=1  and zczt not in(2,7,8) ";//and ztzt<>7
        log.writeLog("获取台式机资产设备总数 关领导视图 huangwm>>"+sql);
        RecordSet rs = new RecordSet();
        rs.execute(sql);
        rs.next();
        return rs.getString("counts");
    }
    /**
     * 获取便携式计算机资产设备总数 关领导视图 huangwm
     * @return
     */
    public String getBxsjsjCount_gld(){
        String sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and b.id=2  and zczt not in(2,7,8) ";//and ztzt<>7
        log.writeLog("获取便携式计算机资产设备总数 关领导视图 huangwm>>"+sql);
        RecordSet rs = new RecordSet();
        rs.execute(sql);
        rs.next();
        return rs.getString("counts");
    }

    /**
     * 获取打印机资产设备总数 关领导视图 huangwm
     * @return
     */
    public String getDyjCount_gld(){
        String sql="select count(1) counts from  uf_swzczmxx a,uf_sbflxx b where a.zclx=b.id  and b.id in(10,11,12,13)  and zczt not in(2,7,8) ";//and ztzt<>7
        log.writeLog("获取打印机资产设备总数 关领导视图 huangwm>>"+sql);
        RecordSet rs = new RecordSet();
        rs.execute(sql);
        rs.next();
        return rs.getString("counts");
    }
    /**
     * 获取资产总值 关领导视图 huangwm
     * @return
     */
    public String getAssetZz_gld(){
        String sql="select sum(isnull(dj,0))/10000 as  djsum  from uf_swzczmxx where  isnull(cqzk,-1) in (0,1) ";
        log.writeLog("获取资产总值 关领导视图 huangwm>>"+sql);
        RecordSet rs = new RecordSet();
        rs.execute(sql);
        rs.next();
        BigDecimal bd = new BigDecimal(rs.getDouble("djsum")).setScale(2, RoundingMode.UP);
        log.writeLog("获取资产总值 关领导视图 huangwm>>"+bd.doubleValue());
        return bd.doubleValue()+"万元";
    }
}
